package com.ruoyi.web.controller.ltd_web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ltd_web.domain.LtdProductDetail;
import com.ruoyi.ltd_web.service.ILtdProductDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品资料Controller
 *
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/system/ltd_product_detail")
public class LtdProductDetailController extends BaseController
{
    @Autowired
    private ILtdProductDetailService ltdProductDetailService;

    /**
     * 查询产品资料列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(LtdProductDetail ltdProductDetail)
    {
        startPage();
        List<LtdProductDetail> list = ltdProductDetailService.selectLtdProductDetailList(ltdProductDetail);
        return getDataTable(list);
    }

    /**
     * 导出产品资料列表
     */
    @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "产品资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LtdProductDetail ltdProductDetail)
    {
        List<LtdProductDetail> list = ltdProductDetailService.selectLtdProductDetailList(ltdProductDetail);
        ExcelUtil<LtdProductDetail> util = new ExcelUtil<LtdProductDetail>(LtdProductDetail.class);
        util.exportExcel(response, list, "产品资料数据");
    }

    /**
     * 获取产品资料详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(ltdProductDetailService.selectLtdProductDetailByDetailId(detailId));
    }

    /**
     * 新增产品资料
     */
    @PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "产品资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LtdProductDetail ltdProductDetail)
    {
        return toAjax(ltdProductDetailService.insertLtdProductDetail(ltdProductDetail));
    }

    /**
     * 修改产品资料
     */
    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "产品资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LtdProductDetail ltdProductDetail)
    {
        return toAjax(ltdProductDetailService.updateLtdProductDetail(ltdProductDetail));
    }

    /**
     * 删除产品资料
     */
    @PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "产品资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(ltdProductDetailService.deleteLtdProductDetailByDetailIds(detailIds));
    }


    @Log(title = "删除产品参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/updateLtdProductDetailStatus/{detailIds}")
    public AjaxResult updateLtdProductDetailStatus(@PathVariable Long[] detailIds)
    {
        return ltdProductDetailService.updateLtdProductDetailStatus(detailIds);
    }

    @Anonymous
//    @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/getProductById/{productId}")
    public AjaxResult getProductById(@PathVariable("productId") Long productId)
    {
        return ltdProductDetailService.getProductById(productId);
    }
}
